<include file="Public/header" title="单条录入"/>
<div id="page-wrapper">

    <div class="row clearfix">
        <div class="col-md-12 column">
            <h3 class="text-center">
                单条信息录入<br>
            </h3>
        </div>
        <div class="col-md-12 column col-md-offset-2">
            <form class="form-horizontal" role="form" action="{:U('Index/singleimport')}" method="post" onSubmit="return checkInput(this)">
                <div class="form-group ">
                    <label for="name" class="col-sm-2 control-label text text-danger">*姓名 :</label>

                    <div class="col-sm-6">
                        <input type="text" class="form-input" id="name" name="name" placeholder="name"/>
                    </div>
                </div>
                <div class="form-group ">
                    <label for="sfzh" class="col-sm-2 control-label text text-danger">*身份证号 :</label>

                    <div class="col-sm-6">
                        <input type="text" class="form-input" id="sfzh" name="sfzh" placeholder="card id"/>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">性别 :</label>

                    <div class="controls col-sm-6">
                        <label>
                            <input type="radio" name="sex" id="sex_male" value="1" checked="">
                            男</label>
                        <label class="ml20">
                            <input type="radio" name="sex" id="sex_famale" value="0">
                            女</label>
                    </div>

                </div>

                <div class="form-group ">
                    <label for="mz" class="col-sm-2 control-label">民族 :</label>

                    <div class="col-sm-6">
                        <input type="text" class="form-input" id="mz" name="mz" placeholder="minzu"/>
                    </div>
                </div>

                <div class="form-group ">
                    <label for="resident" class="col-sm-2 control-label">户籍地址 :</label>

                    <div class="col-sm-6">
                        <input type="text" class="form-input" id="resident" name="resident" placeholder="resident"/>
                    </div>
                </div>

                <div class="form-group ">
                    <label for="resident_current" class="col-sm-2 control-label">实际地址 :</label>

                    <div class="col-sm-6">
                        <input type="text" class="form-input" id="resident_current" name="resident_current"
                               placeholder="current resident"/>
                    </div>
                </div>

                <div class="form-group ">
                    <label for="type" class="col-sm-2 control-label text text-danger">*人员类型 :</label>

                    <div class="col-sm-6">
                        <input type="text" class="form-input" id="type" name="type" placeholder="type"/>
                    </div>
                </div>

                <div class="form-group ">
                    <label for="risk_grade" class="col-sm-2 control-label">风险等级 :</label>

                    <div class="col-sm-6">
                        <input type="text" class="form-input" id="risk_grade" name="risk_grade"
                               placeholder="grade of risk"/>
                    </div>
                </div>

                <div class="form-group">
                    <label for="polices" class="col-sm-2 control-label text text-danger">*管辖民警 :</label>

                    <div class="col-sm-6">
                        <input type="text" class="form-input" name="polices" id="polices"/>
                    </div>
                </div>

                <div class="form-group">
                    <label for="p_tel" class="col-sm-2 control-label text text-danger">*联系方式 :</label>

                    <div class="col-sm-6" id="moreTele">
                        <input type="hidden" id="p_tel" name="p_tel">
                        <input type="tel" id="p_tel2" class="form-input" name="tele" placeholder="phone of police">
                        <a class="plus-tele" id="telPlus" num="1">＋</a>
                        <a class="plus-tele" style="display:none;" id="telMinus" name="telMinus">－</a>
                    </div>
                </div>

                <div class="form-group">
                    <label for="p_dept" class="col-sm-2 control-label">管理单位 :</label>

                    <div class="col-sm-6">
                        <input type="text" class="form-input" id="p_dept" name="p_dept"/>
                    </div>
                </div>

                <div class="form-group">
                    <label for="p_type" class="col-sm-2 control-label">警种 :</label>

                    <div class="col-sm-6">
                        <input type="text" class="form-input" id="p_type" name="p_type"/>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-success">提交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript">
    var phones;
    teleInputBlur();

    // 点击添加一行手机号输入
    $('#telPlus').on('click', function () {
        var teleNum = parseInt($(this).attr('num'));
        if (teleNum < 3) {
            $(this).attr('num', ++teleNum);
            var cloneInput = $('#p_tel').next().clone(true);
            var cloneAddIcon = $('#telMinus').clone(true);
            $('#moreTele').append(cloneInput.val('').addClass('mt10')).append(cloneAddIcon.show().removeAttr('id'));
            teleInputBlur();
            // 点击删除一行电话记录
            $('a[name=telMinus]').unbind('click');
            $('a[name=telMinus]').on('click', function () {
                var tele = $(this).prev().val();
                $('#telPlus').attr('num', parseInt($('#telPlus').attr('num')) - 1);
                $(this).prev().remove();
                $(this).remove();
                if (!jQuery.isEmptyObject(tele)) {
                    phones.pop(tele);
                }
                if (phones && phones.length > 0) {
                    $('#p_tel').val(phones.join('#'));
                }
            });
        }
    });


    // 点击删除一行电话记录
    $('a[name=telMinus]').unbind('click');
    $('a[name=telMinus]').on('click', function () {
        var tele = $(this).prev().val();
        $('#telPlus').attr('num', parseInt($('#telPlus').attr('num')) - 1);
        $(this).prev().remove();
        $(this).remove();
        if (!jQuery.isEmptyObject(tele)) {
            phones.pop(tele);
        }
        if (phones && phones.length > 0) {
            $('#p_tel').val(phones.join('#'));
        }
    });

    // 电话输入框失去焦点事件
    function teleInputBlur() {
        $('input[name=tele]').unbind('click');
        $('input[name=tele]').blur(function () {
            phones = [];
            $('input[name=tele]').each(function () {
                var tele = $(this).val();
                if (!jQuery.isEmptyObject(tele)) {
                    if (phones.indexOf($(this).val()) <= -1) {
                        phones.push($(this).val());
                    }
                }
            });
            if (phones.length > 0) {
                $('#p_tel').val(phones.join('#'));
            }
        });
    }


    function checkInput(form) {
        if (form.name.value.replace(/(^\s*)|(\s*$)/g, "") == "") {

            var d = dialog({
                content: '请输入姓名',
                align: 'right',
                quickClose: true
            });

            d.show(document.getElementById('name'));
        }
        else if (form.sfzh.value.replace(/(^\s*)|(\s*$)/g, "") == "") {
            var d = dialog({
                content: '请输入身份证号',
                align: 'right',
                quickClose: true
            });

            d.show(document.getElementById('sfzh'));
        }

        else if (form.type.value.replace(/(^\s*)|(\s*$)/g, "") == "") {
            var d = dialog({
                content: '请输入人员类型',
                align: 'right',
                quickClose: true
            });

            d.show(document.getElementById('type'));
        }

        else if (form.polices.value.replace(/(^\s*)|(\s*$)/g, "") == "") {
            var d = dialog({
                content: '请输入管辖民警',
                align: 'right',
                quickClose: true
            });

            d.show(document.getElementById('polices'));
        }

        else if (form.p_tel.value.replace(/(^\s*)|(\s*$)/g, "") == "") {
            var d = dialog({
                content: '请输入联系方式',
                align: 'right',
                quickClose: true
            });

            d.show(document.getElementById('p_tel2'));
        }
        if (d != null) {
            setTimeout(function () {
                d.close().remove();
            }, 2000);

            return false;
        }
        return true;
    }

</script>
<include file="Public/footer"/>